// 响应接口
import { request } from 'boot/axios';

export interface GetTmsTemplateByIdRes {
  code: number;
  message: string;
  data: {
    code: number;
    message: string;
    data: {
      id: number;
      name: string;
      tag: string;
      content: string;
      lang: string;
      comment: string;
      src: number;
      root: number;
      postfix: string;
      generateNum: number;
      release: number;
      componentName: string;
      type: number;
    };
  };
}

/**
 * 通过id查询模板表
 * @param {string} id
 * @returns
 */
export function getTmsTemplateById(id: number): Promise<GetTmsTemplateByIdRes> {
  return request.get(`/portal/open/template/${id}`);
}

// 响应接口
export interface LoginRes {
  code: number;
  message: string;
  data: {
    code: number;
    message: string;
    data: string;
  };
}

/**
 * 用户名密码登录
 * @param {string} username 用户名
 * @param {string} password 密码
 * @returns
 */
export function login(username: string, password: string): Promise<LoginRes> {
  return request.get(
    `/admin/open/passWord?username=${username}&password=${password}`
  );
}

// 响应接口
export interface GetMineTemplateRes {
  code: number;
  message: string;
  data: {
    code: number;
    message: string;
    data: {
      id: number;
      templateId: number;
    }[];
  };
}

/**
 * 通过id查询我的模板表
 * @returns
 */
export function getMineTemplate(): Promise<GetMineTemplateRes> {
  return request.get('/portal/api/mineTemplate');
}

// 响应接口
export interface GetByIdRes {
  code: number;
  message: string;
  data: {
    code: number;
    message: string;
    data: {
      id: number;
      memberLevelId: number;
      username: string;
      password: string;
      nickname: string;
      phone: string;
      payCode: string;
      icon: string;
      gender: string;
      birthday: Record<string, unknown>;
      city: string;
      job: string;
      personalizedSignature: string;
      sourceType: string;
      integration: number;
      growth: number;
      luckyCount: number;
      historyIntegration: number;
      thirdType: string;
      thirdKey: string;
      open_id: string;
    };
  };
}

/**
 * 通过id查询会员表
 * @returns
 */
export function getUserById(): Promise<GetByIdRes> {
  return request.get('/admin/api/ums-member');
}

// 响应接口
export interface GetMallRes {
  code: number;
  message: string;
  data: string;
}

/**
 * 获取邮箱验证码
 * @param {string} mail 接受邮箱
 * @returns
 */
export function getMall(mail: string): Promise<GetMallRes> {
  return request.get(`/admin/open/getMall/${mail}`);
}

// 响应接口
export interface GetOnlineRes {
  code: number;
  message: string;
  data: {
    code: number;
    message: string;
    data: {
      id: string;
      client: string;
    }[];
  };
}

/**
 * 获取我的在线数据
 * @returns
 */
export function getOnline(): Promise<GetOnlineRes> {
  return request.post('/portal/open/send/GetOnline');
}

// 参数接口
export interface SendParams {
  id?: number[];
  client?: Record<string, unknown>[];
  msg?: string;
}

// 响应接口
export interface SendRes {
  code: number;
  message: string;
  data: {
    id: string;
    client: string;
  }[];
}

/**
 * 发送消息到id
 * @param {object} params WSSendMsg
 * @param {array} params.id
 * @param {array} params.client
 * @param {string} params.msg
 * @returns
 */
export function send2Id(params: SendParams): Promise<SendRes> {
  return request.post('/portal/open/send/SendIds', params);
}

// 参数接口
export interface SaveOne_10Params {
  database?: string;
  global?: string;
  host?: string;
  id?: number;
  name?: string;
  nickname?: string;
  password?: string;
  port?: number;
  save?: string;
  type?: string;
  username?: string;
}

// 响应接口
export interface SaveOne_10Res {
  code: number;
  message: string;
  data: {
    code: number;
    message: string;
    data: string;
  };
}

/**
 * 添加一个用户数据库连接配置表
 * @param {object} params 用户数据库连接配置表
 * @param {string} params.database 数据库名称
 * @param {string} params.global 全局
 * @param {string} params.host 数据库地址
 * @param {number} params.id
 * @param {string} params.name 连接别名
 * @param {string} params.nickname 昵称
 * @param {string} params.password 密码
 * @param {number} params.port 端口
 * @param {string} params.save 保存
 * @param {string} params.type 数据库类型
 * @param {string} params.username 用户名
 * @returns
 */
export function cmsDatasourceConfig(
  params: SaveOne_10Params
): Promise<SaveOne_10Res> {
  return request.post('/admin/api/gen/cmsDatasourceConfig', params);
}

// 响应接口
export interface DeleteById_10Res {
  code: number;
  message: string;
  data: {
    code: number;
    message: string;
    data: boolean;
  };
}

/**
 * 根据主键删除用户数据库连接配置表
 * @param {string} id
 * @returns
 */
export function deleteCmsDatasourceConfig(
  id: number
): Promise<DeleteById_10Res> {
  return request.delete(`/admin/api/gen/cmsDatasourceConfig/${id}`);
}
